﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace WPFGame.Windows
{
    /// <summary>
    /// UserControl1.xaml 的交互逻辑
    /// </summary>
    public partial class UserControl1 : UserControl
    {
        Ellipse ell;
        public UserControl1()
        {
            InitializeComponent();
            ell = new Ellipse()
            {
                Width= 50,
                Height=50,
                Fill = new SolidColorBrush(Colors.OrangeRed),
            };
            canvas.Children.Add(ell);
            Canvas.SetLeft(ell, 100);
            Canvas.SetTop(ell, 100);
        }

        private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Storyboard storyboard = new Storyboard();
            Point p = e.GetPosition(canvas);
            DoubleAnimation da1 = new DoubleAnimation()
            {
                Duration = TimeSpan.FromMilliseconds(400),
                From = Canvas.GetLeft(ell),
                To = p.X
            };
            Storyboard.SetTarget(da1, ell);
            Storyboard.SetTargetProperty(da1, new PropertyPath("(Canvas.Left)"));
            storyboard.Children.Add(da1);

            DoubleAnimation da2 = new DoubleAnimation()
            {
                Duration = TimeSpan.FromMilliseconds(400),
                From = Canvas.GetTop(ell),
                To = p.Y
            };
            Storyboard.SetTarget(da2, ell);
            Storyboard.SetTargetProperty(da2, new PropertyPath("(Canvas.Top)"));
            storyboard.Children.Add(da2);
            if (!Resources.Contains("storyboard"))
                Resources.Add("storyboard", storyboard);
            storyboard.Begin();
        }
    }
}
